package com.goldsign.pay.provider.user.controller;

import com.goldsign.pay.provider.user.to.AccountRegisterRespDTO;
import com.goldsign.pay.common.log.SysLog;
import com.goldsign.pay.common.to.ServiceResponseDTO;
import com.goldsign.pay.common.util.ApiHelpUtil;
import com.goldsign.pay.provider.user.service.AccountRegisterService;
import com.goldsign.pay.provider.user.to.AccountRegisterReqDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by xiaojingjing on 2018/5/11.
 */
@RestController
public class AppRegisterController {
    @Autowired
    private AccountRegisterService accountRegisterService;

    /**
     * 账户注册第一步【获取验证码】
     * @param registerReq
     * @param request
     * @param response
     */
    @RequestMapping("/accountRegisterForAppStepOne")
    public void accountRegisterForAppStepOne(AccountRegisterReqDTO registerReq , HttpServletRequest request , HttpServletResponse response){
        SysLog.info(request);

        try {
            registerReq = accountRegisterService.initParam(registerReq,request);
            SysLog.info("【accountRegisterForAppStepOne】收到的请求参数："+registerReq.toString());
            AccountRegisterRespDTO accountRegisterRespDTO = accountRegisterService.accountRegisterForAppStepOne(registerReq);

            ServiceResponseDTO serviceResponse = new ServiceResponseDTO(accountRegisterRespDTO.getResp_code(),accountRegisterRespDTO.getResp_msg());
            serviceResponse.putEntry("order",accountRegisterRespDTO);
            ApiHelpUtil.apiReturn(serviceResponse, response);
        } catch (Exception e) {
            ApiHelpUtil.writeServerError(response, "服务异常");
            e.printStackTrace();
        }
    }

    /**
     * 账户注册第二步【验证验证码】
     * @param registerReq
     * @param request
     * @param response
     */
    @RequestMapping("/accountRegisterForAppStepTwo")
    public void accountRegisterForAppStepTwo(AccountRegisterReqDTO registerReq , HttpServletRequest request , HttpServletResponse response){
        SysLog.info(request);

        try {
            registerReq = accountRegisterService.initParam(registerReq,request);
            SysLog.info("【accountRegisterForAppStepOne】收到的请求参数："+registerReq.toString());
            AccountRegisterRespDTO accountRegisterRespDTO = accountRegisterService.accountRegisterForAppStepTwo(registerReq);

            ServiceResponseDTO serviceResponse = new ServiceResponseDTO(accountRegisterRespDTO.getResp_code(),accountRegisterRespDTO.getResp_msg());
            serviceResponse.putEntry("order",accountRegisterRespDTO);
            ApiHelpUtil.apiReturn(serviceResponse, response);
        } catch (Exception e) {
            ApiHelpUtil.writeServerError(response, "服务异常");
            e.printStackTrace();
        }
    }

    /**
     * 账户注册第三步【提交开通账户】
     * @param registerReq
     * @param request
     * @param response
     */
    @RequestMapping("/accountRegisterForAppStepThree")
    public void accountRegisterForAppStepThree(AccountRegisterReqDTO registerReq , HttpServletRequest request , HttpServletResponse response){
        SysLog.info(request);

        try {
            registerReq = accountRegisterService.initParam(registerReq,request);
            SysLog.info("【accountRegisterForAppStepOne】收到的请求参数："+registerReq.toString());
            AccountRegisterRespDTO accountRegisterRespDTO = accountRegisterService.accountRegisterForAppStepThree(registerReq);

            ServiceResponseDTO serviceResponse = new ServiceResponseDTO(accountRegisterRespDTO.getResp_code(),accountRegisterRespDTO.getResp_msg());
            serviceResponse.putEntry("user",accountRegisterRespDTO);
            ApiHelpUtil.apiReturn(serviceResponse, response);
        } catch (Exception e) {
            ApiHelpUtil.writeServerError(response, "服务异常");
            e.printStackTrace();
        }
    }


}
